package com.javacore;

import java.time.LocalDate;
import java.util.Date;
import java.util.Objects;

public class Employee implements Comparable<Employee>,Cloneable{



    private double salary;
    private LocalDate hireday;
    private String name;

    public void setSalary(double salary) {
        this.salary = salary;
    }

    public void setHireday(LocalDate hireday) {
        this.hireday = hireday;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Employee clone () throws CloneNotSupportedException {
        return (Employee) super.clone();
    }

    /**
     * 提高员工的工资
     * @param bypercent 涨薪的比率
     * @return void
     */

    public void raise_salary(double bypercent){
        salary += ((salary * bypercent) / 100);
    }

    public int compareTo(Employee obj) {
        if (salary > obj.getSalary())
            return 1;
        else if (salary < obj.getSalary())
            return -1;
        else
            return 0;
        //return Double.compare(salary,e.salary);

        //compare接口实现基本方法，此乃升序。

    }
    /**
     * equals方法的重写应该讲究一下特点
     * 对称性：就好比 x.equals(y) ,y.equals(y) 的结果相同
     * 传递性： y.equals(z)返回true，x.equals(z)返回true 那么x.equals(y) 也应该返回true
     * 自反性：见名知义 x.equals(x) return true
     * @param obj
     * @return
     */
    public boolean equals(Object obj){
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (this.getClass() != obj.getClass())
            return false;



        return true;

    }

    public int hashcode(){
        return Objects.hash(name,salary,hireday);
    }


    public Employee(double salary,int year,int month,int day , String name) {
       this.name = name;
        this.salary = salary;
        this.hireday = LocalDate.of(year,month,day);

    }

    public double getSalary() {
        return salary;
    }
    
    public String getName() {
        return name;
    }

    public LocalDate getHireday() {
        return hireday;
    }



    public int hashCode(){
        //每一个对象的哈希码基本上不同，基本上我们是要重写hashcode方法
        //而对于默认的hascode其值由其地址得出  hashcode来自Object超类
        /**
         * hashcode方法是较好的一种，写法简单，
         * 该方法会对每个实际参数调用   java.util.Objects 的static hashCode(Object)
         *如果对象为null则返回 0；
         */
        return Objects.hash(this.hireday,this.name,this.salary);

    }


    @Override
    public String toString() {
        return "Employee{" +
                "salary=" + salary +
                ", hireday=" + hireday +
                ", name='" + name + '\'' +
                '}';
    }


}
